call plug#begin('~/.config/nvim/plugged')
" 主题
Plug 'joshdick/onedark.vim'
" 状态栏
Plug 'vim-airline/vim-airline'
" 模糊查找
Plug 'Yggdroot/LeaderF', { 'do': ':LeaderfInstallCExtension' }
" 补全框架
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" 代码片段
Plug 'honza/vim-snippets' 
" Undo树
Plug 'mbbill/undotree'
Plug 'easymotion/vim-easymotion'
" Python语义化高亮
Plug 'numirias/semshi', { 'do': ':UpdateRemotePlugins', 'for' :['python', 'vim-plug'] }
" 重复插件
Plug 'tpope/vim-repeat'
" Markdown插件
Plug 'tweekmonster/braceless.vim', { 'for' :['python', 'vim-plug'] }
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle', 'for': ['text', 'markdown', 'vim-plug'] }
Plug 'mzlogin/vim-markdown-toc', { 'for': ['gitignore', 'markdown', 'vim-plug'] }
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
" 书签增强
Plug 'MattesGroeger/vim-bookmarks'
" 颜色显示
Plug 'rrethy/vim-hexokinase', { 'do': 'make hexokinase' }
" git工具
Plug 'tpope/vim-fugitive'
"多光标插件
Plug 'mg979/vim-visual-multi' 
"悬浮终端
Plug 'voldikss/vim-floaterm' 
"代码注释插件
Plug 'tomtom/tcomment_vim'    
" 快速修改成对符号
Plug 'tpope/vim-surround'
" 突出显示(下划线)与光标所在相同的词
Plug 'RRethy/vim-illuminate'  
" 模糊查找
Plug 'liuchengxu/vista.vim'
" markdown ctag支持
Plug 'jszakmeister/markdown2ctags'
"权限提升插件
Plug 'lambdalisue/suda.vim'    
" 快速替换
Plug 'brooth/far.vim', { 'on': ['F', 'Far', 'Fardo'] }
" 彩虹括号
Plug 'luochen1990/rainbow'
" 代码调试
Plug 'puremourning/vimspector', {'do': './install_gadget.py --enable-python --enable-bash'}
call plug#end()

"vim-monokai settings
" onedark.vim settings
color onedark
set background=dark
" 半透明
highlight Normal guibg=NONE ctermbg=None

" LeaderF settings
let g:Lf_HideHelp = 1
let g:Lf_UseCache = 0
let g:Lf_UseVersionControlTool = 0
let g:Lf_IgnoreCurrentBufferName = 1
" popup mode
let g:Lf_WindowPosition = 'popup'
let g:Lf_PreviewInPopup = 1
let g:Lf_StlSeparator = { 'left': "\ue0b0", 'right': "\ue0b2", 'font': "DejaVu Sans Mono for Powerline" }
let g:Lf_PreviewResult = {'Function': 0, 'BufTag': 0 }
let g:Lf_CommandMap = {'<C-P>': ['<Up>'], '<C-N>': ['<Down>']}


" vim-table-mode settings
autocmd FileType markdown TableModeEnable

" undotree settings
let g:undotree_DiffAutoOpen = 1
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_ShortIndicators = 1
let g:undotree_WindowLayout = 2
let g:undotree_DiffpanelHeight = 8
let g:undotree_SplitWidth = 24

" vim-floaterm settings
let g:floaterm_width = 0.8
let g:floaterm_height = 0.8


" vim-airline settings
let g:airline#extensions#tabline#enabled = 1
" let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#formatter = 'default'
" let g:airline#extensions#tabline#buffer_nr_show = 0
let g:airline#extensions#tabline#fnametruncate = 16
let g:airline#extensions#tabline#fnamecollapse = 2
" let g:airline#extensions#tabline#buffer_idx_mode = 1


" vim-markdown-toc settings
let g:vmt_cycle_list_item_markers = 1
let g:vmt_fence_text = 'TOC'
let g:vmt_fence_closing_text = '/TOC'
" let g:vmt_auto_update_on_save = 1
" let g:vmt_dont_insert_fence = 1


" markdown-preview.nvim settings
let g:mkdp_auto_start = 0
let g:mkdp_auto_close = 1
let g:mkdp_markdown_css = ''
let g:mkdp_highlight_css = ''


" vim-bookmarks settings
let g:bookmark_no_default_key_mappings = 1
let g:bookmark_save_per_working_dir = 1
let g:bookmark_auto_save = 1
let g:bookmark_highlight_lines = 1
let g:bookmark_manage_per_buffer = 1
let g:bookmark_save_per_working_dir = 1
let g:bookmark_center = 1
let g:bookmark_auto_close = 1
let g:bookmark_location_list = 1


" vim-hexokinase settings
let g:Hexokinase_highlighters = ['foreground']


" vim-illuminate settings
let g:Illuminate_delay = 750
hi illuminatedWord cterm=undercurl gui=undercurl

" suda settings
cnoreabbrev sudowrite w suda://%
cnoreabbrev sw w suda://%


" rawinbow settings
let g:rainbow_active = 1


" vimspector settings
let g:vimspector_enable_mappings = 'HUMAN' "使用官方快捷键
function! s:read_template_into_buffer(template) "加载模板文件
	" has to be a functio                                                             n to avoid the extra space fzf#run insers otherwise
	execute '0r ~/.config/nvim/sample_vimspector_json/'.a:template
endfunction
command! -bang -nargs=* LoadVimSpectorJsonTemplate call fzf#run({
			\   'source': 'ls -1 ~/.config/nvim/sample_vimspector_json',
			\   'down': 20,
			\   'sink': function('<sid>read_template_into_buffer')
			\ })
sign define vimspectorBP text=☛ texthl=Normal
sign define vimspectorBPDisabled text=☞ texthl=Normal
sign define vimspectorPC text=🔶 texthl=SpellBad


" tcomment_vim settings
let g:tcomment_textobject_inlinecomment = ''

" vista.vim
function! NearestMethodOrFunction() abort
	return get(b:, 'vista_nearest_method_or_function', '')
endfunction

set statusline+=%{NearestMethodOrFunction()}

" By default vista.vim never run if you don't call it explicitly.
"
" If you want to show the nearest function in your statusline automatically,
" you can add the following line to your vimrc
autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
let g:vista_icon_indent = ["╰─▸ ", "├─▸ "]
let g:vista_default_executive = 'ctags'
let g:vista_executive_for = {
			\ 'cpp': 'coc',
			\ 'php': 'coc',
			\ }
let g:vista_ctags_cmd = {
			\ 'haskell': 'hasktags -x -o - -c',
			\ }
let g:vista_fzf_preview = ['right:50%']
let g:vista#renderer#enable_icon = 1
let g:vista#renderer#icons = {
			\   "function": "\uf794",
			\   "variable": "\uf71b",
			\  }
" markdown2ctags
let g:tagbar_type_markdown = {
    \ 'ctagstype': 'markdown',
    \ 'ctagsbin' : '~/.config/nvim/plugged/markdown2ctags/markdown2ctags.py',
    \ 'ctagsargs' : '-f - --sort=yes --sro=»',
    \ 'kinds' : [
        \ 's:sections',
        \ 'i:images'
    \ ],
    \ 'sro' : '»',
    \ 'kind2scope' : {
        \ 's' : 'section',
    \ },
    \ 'sort': 0,
\ }
" coc
let g:coc_global_extensions = [
			\'coc-explorer',
			\'coc-json',
			\'coc-marketplace',
			\'coc-lua',
			\'coc-sumneko-lua',
			\'coc-tsserver',
			\'coc-prettier',
			\'coc-jedi',
			\'coc-jedi',
			\'coc-phpls',
			\'coc-emmet',
			\'coc-highlight',
			\'coc-pairs',
			\'coc-translator',
			\'coc-explorer',
			\'coc-snippets',
			\'coc-yank',
			\'coc-git']
" coc-translator
let g:coc_explorer_global_presets = {
\   '.vim': {
\     'root-uri': '~/.config/nvim',
\   },
\   'cocConfig': {
\      'root-uri': '~/.config/coc',
\   },
\   'tab': {
\     'position': 'tab',
\     'quit-on-open': v:true,
\   },
\   'floating': {
\     'position': 'floating',
\     'open-action-strategy': 'sourceWindow',
\   },
\   'floatingTop': {
\     'position': 'floating',
\     'floating-position': 'center-top',
\     'open-action-strategy': 'sourceWindow',
\   },
\   'floatingLeftside': {
\     'position': 'floating',
\     'floating-position': 'left-center',
\     'floating-width': 50,
\     'open-action-strategy': 'sourceWindow',
\   },
\   'floatingRightside': {
\     'position': 'floating',
\     'floating-position': 'right-center',
\     'floating-width': 50,
\     'open-action-strategy': 'sourceWindow',
\   },
\   'simplify': {
\     'file-child-template': '[selection | clip | 1] [indent][icon | 1] [filename omitCenter 1]'
\   },
\   'buffer': {
\     'sources': [{'name': 'buffer', 'expand': v:true}]
\   },
\ }

function! s:check_back_space() abort
	let col = col('.') - 1
	return !col || getline('.')[col - 1]  =~ '\s'
endfunction


" use normal command like `<leader>xi(`
" Coc-pairs settings
autocmd FileType vim let b:coc_pairs_disable = ['"']

function! s:show_documentation()
  if (index(['vim','help'], &filetype) >= 0)
    execute 'h '.expand('<cword>')
  elseif (coc#rpc#ready())
    call CocActionAsync('doHover')
  else
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

" coc-snippets
imap <C-l> <Plug>(coc-snippets-expand)
let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev = '<S-Tab>'
xmap <leader>x  <Plug>(coc-convert-snippet) "添加选中文本到snippets


function! s:cocActionsOpenFromSelected(type) abort
  execute 'CocCommand actions.open ' . a:type
endfunction
